package org.monkey.spring;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MonkeyDynamicProxyAopHandler implements InvocationHandler {

    private Object target;

    public MonkeyDynamicProxyAopHandler(Object target) {
        this.target = target;
    }

    public <T> T getProxy() {
        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                this);
    }

   // 创建动态代理
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("proxy增强");
        return method.invoke(target,args);
        // 后置处理
    }
}
